cc.Class({
    extends: cc.Component,

    properties: {
        // defaults, set visually when attaching this script to the Canvas
        chooseLayer:{
            default:null,
            type:cc.Node
        },
        btn:{
            default:null,
            type:cc.Button
        },
        map:{
            default:null,
            type:cc.Node
        }
    },

    // use this for initialization
    onLoad: function () {
        this._isShow = true;

               //添加事件监听
        this.node.on(cc.Node.EventType.TOUCH_START,function(event){
            // console.log("touch begin");
            this.touchBegan(event);
        },this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE,function(event){
            // console.log("touch move");
            this.touchMoved(event);
        },this);
        this.node.on(cc.Node.EventType.TOUCH_END,function(event){
            // console.log("touch end");
            this.touchEnd(event);
        },this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL,function(event){
            // console.log("touch cancel");
        },this);
    },

        //触摸监听
    touchBegan:function(event){
    },

    touchMoved:function(event){
    },

    touchEnd:function(event){
        var clickPos = event.getLocation();
        var tiledmap = this.map.getComponent('TiledMapMgr');
        if(tiledmap){
            tiledmap.clickEvent(clickPos);
        }
    },

    onBtnClicked:function(){
        this._isShow = !this._isShow;
        this.updateBtnState();
        this.showLayerAction();
    },

    updateBtnState:function(){
        if(this._isShow){
            this.btn.node.scaleX = 1
        }else{
            this.btn.node.scaleX = -1
        }
    },  

    showLayerAction:function(){
        if(!this.chooseLayer)
            return;
        if(this._isShow){
            this.chooseLayer.runAction(cc.moveTo(0.2,cc.p(-this.node.width/2+this.chooseLayer.width/2,this.chooseLayer.y)));
        }else{
            this.chooseLayer.runAction(cc.moveTo(0.2,cc.p(-this.node.width/2-this.chooseLayer.width/2,this.chooseLayer.y)));
        }
    },

    // called every frame
    update: function (dt) {

    },
});
